package cn.tedu.response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/ResponseServlet")
public class ResponseServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //response中防止中文乱码的固定写法
        response.setContentType("text/html;charset=utf-8");
        //给浏览器响应数据
        //1.获取一个写出流
        PrintWriter out = response.getWriter();
        //2.正式写出数据--写到浏览器
        out.write("hello servlet1...");
        out.write("hello servlet2...");
        out.write("hello servlet3...");
        out.write("hello servlet4...");
        //中文一定乱码
        out.write("你好 servlet4...");


    }
}
